using System;
using System.Collections.Generic;
using Csla;
using Ent.AccesoDatos;

namespace Ent.Inscripcion.Core.Core
{
    [Serializable]
    public class RegistroTutoriaLista :
      ReadOnlyListBase<RegistroTutoriaLista, RegistroTutoriaInfo>
    {

        #region Factory Methods

        public static RegistroTutoriaLista GetRegistroTutoriaLista(string filter)
        {
            return DataPortal.Fetch<RegistroTutoriaLista>(
              new SingleCriteria<RegistroTutoriaLista, string>(filter));
        }

        private RegistroTutoriaLista()
        { /* require use of factory methods */ }

        #endregion


        #region Data Access

        private void DataPortal_Fetch(
          SingleCriteria<RegistroTutoriaLista, string> criteria)
        {
            RaiseListChangedEvents = false;
            IsReadOnly = false;

            var accesoDatos = new DriveDataBase(TypeDataBase.Mysql);
            var parametros = new List<Parametro> {new Parametro("Estudiante", criteria.Value)};
            var datos = accesoDatos.EjecutarReader("ObtenerInscripciones", parametros);
            while (datos.Datos.Read())
            {
                Add(RegistroTutoriaInfo.GetRegistroTutoriaInfo(datos));
            }
            if (!datos.Datos.IsClosed) datos.Datos.Close();
            IsReadOnly = true;
            RaiseListChangedEvents = true;
        }

        #endregion
    }


    [Serializable]
    public class RegistroTutoriaInfo : ReadOnlyBase<RegistroTutoriaInfo>
    {
        #region Business Methods

        private static PropertyInfo<Guid> IdProperty = RegisterProperty<Guid>(o => o.Id, "Name");
        public Guid Id
        {
            get { return GetProperty(IdProperty); }
        }

        private static PropertyInfo<string> EstudianteIdProperty = RegisterProperty<string>(o => o.EstudianteId, "Name");
        public string EstudianteId
        {
            get { return GetProperty(EstudianteIdProperty); }
        }

        private static PropertyInfo<string> HorarioIdProperty = RegisterProperty<string>(o => o.HorarioId, "Name");
        public string HorarioId
        {
            get { return GetProperty(HorarioIdProperty); }
        }

        private static PropertyInfo<string> DiaIdProperty = RegisterProperty<string>(o => o.DiaId, "Name");
        public string DiaId
        {
            get { return GetProperty(DiaIdProperty); }
        }

        private static PropertyInfo<string> NivelIdProperty = RegisterProperty<string>(o => o.NivelId, "Name");
        public string NivelId
        {
            get { return GetProperty(NivelIdProperty); }
        }

        private static PropertyInfo<DateTime> FechaProperty = RegisterProperty<DateTime>(o => o.Fecha, "Name");
        public DateTime Fecha
        {
            get { return GetProperty(FechaProperty); }
        }

        private static PropertyInfo<DateTime> HoraProperty = RegisterProperty<DateTime>(o => o.Hora, "Name");
        public DateTime Hora
        {
            get { return GetProperty(HoraProperty); }
        }

        private static PropertyInfo<string> EstadoProperty = RegisterProperty<string>(o => o.Estado, "Name");
        public string Estado
        {
            get { return GetProperty(EstadoProperty); }
        }

        private static PropertyInfo<string> NumeroFacturaProperty = RegisterProperty<string>(o => o.NumeroFactura, "Name");
        public string NumeroFactura
        {
            get { return GetProperty(NumeroFacturaProperty); }
        }

        private static PropertyInfo<int> NumeroCambiosProperty = RegisterProperty<int>(o => o.NumeroCambios, "Name");
        public int NumeroCambios
        {
            get { return GetProperty(NumeroCambiosProperty); }
        }

        private static PropertyInfo<string> DiaProperty = RegisterProperty<string>(o => o.Dia, "Name");
        public string Dia
        {
            get { return GetProperty(DiaProperty); }
        }

        private static PropertyInfo<string> NivelProperty = RegisterProperty<string>(o => o.Nivel, "Name");
        public string Nivel
        {
            get { return GetProperty(NivelProperty); }
        }

        private static PropertyInfo<string> AulaProperty = RegisterProperty<string>(o => o.Aula, "Name");
        public string Aula
        {
            get { return GetProperty(AulaProperty); }
        }

        private static PropertyInfo<string> ParaleloProperty = RegisterProperty<string>(o => o.Paralelo, "Name");
        public string Paralelo
        {
            get { return GetProperty(ParaleloProperty); }
        }

        private static PropertyInfo<string> DocenteProperty = RegisterProperty<string>(o => o.Docente, "Name");
        public string Docente
        {
            get { return GetProperty(DocenteProperty); }
        }               

        
        #endregion

        #region Factory Methods

        internal static RegistroTutoriaInfo GetRegistroTutoriaInfo(Reader childData)
        {
            return DataPortal.FetchChild<RegistroTutoriaInfo>(childData);
        }

        private RegistroTutoriaInfo()
        { /* require use of factory methods */ }

        #endregion
        
        #region Data Access

        private void Child_Fetch(Reader datos)
        {
            LoadProperty(IdProperty, Guid.Parse(datos.Datos.GetString(0)));
            LoadProperty(EstudianteIdProperty, datos.Datos.GetString(1));
            LoadProperty(HorarioIdProperty, datos.Datos.GetString(2));
            LoadProperty(NivelIdProperty, datos.Datos.GetString(3));
            LoadProperty(FechaProperty, DateTime.Parse(datos.Datos.GetString(4)));
            LoadProperty(HoraProperty, DateTime.Parse(datos.Datos.GetString(5)));
            LoadProperty(EstadoProperty, datos.Datos.GetString(6));
            LoadProperty(NumeroFacturaProperty, datos.Datos.GetString(7));
            LoadProperty(NumeroCambiosProperty, datos.Datos.GetInt32(8));
            LoadProperty(AulaProperty, datos.Datos.GetString(9));
            LoadProperty(DiaProperty, datos.Datos.GetString(10));
            LoadProperty(NivelProperty, datos.Datos.GetString(11));
            LoadProperty(ParaleloProperty, datos.Datos.GetString(12));
            LoadProperty(DocenteProperty, string.Format("{1} {0}", datos.Datos.GetString(13), datos.Datos.GetString(14)));            
            
        }

        #endregion
    }
}
